﻿using Models;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;

namespace CentralMonitoring
{
    public partial class test : Form
    {
        public test()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 公司测试平台
            //{ "id":"106","sys":{ "ack":0},"params":{ "topic":"mgzx5183","ppm":193,"temp":29.6,"viscosity":590.11,"density":0.838,"dc":2.330,"water_aw":0.53,"water_vol":0.01,"fe6":0,"fe7":0,"fe8":0,"fe9":0,"fe10":0,"fe11":0,"fe12":0,"fe13":0,"fe14":0,"fe15":0,"nfe6":0,"nfe7":0,"nfe8":0,"nfe9":0},"version":"1.0","method":"thing.event.property.post"}
            //string text = textBox1.Text;
            //int index = text.IndexOf('}');
            //if (text.IndexOf('}') > -1)
            //{
            //    //text = text.Substring(index, text.Length - index);
            //    //text = text.Replace("thing.event.property.post", "@");
            //    //string[] str = text.Split('@');
            //    //text = str[0] + "thing.event.property.post\"}";
            //    JObject relVo = (JObject)JsonConvert.DeserializeObject(text);
            //    if (relVo != null)
            //    {
            //        string msg = relVo["params"].ToString();
            //        Msg vo = JsonConvert.DeserializeObject<Msg>(msg);
            //        DeviceInfo data = new DeviceInfo();
            //        data.DeviceMac = vo.topic.Substring(2, vo.topic.Length - 2);
            //        data.Temp = vo.temp;
            //        data.Vis = vo.viscosity;
            //        data.Dens = vo.density;
            //        data.Dc = vo.dc;
            //        data.Ppm = vo.ppm;
            //        data.Aw = vo.water_aw;
            //        data.Vol = vo.water_vol;
            //        data.Fe1 = vo.fe6;
            //        data.Fe2 = vo.fe7;
            //        data.Fe3 = vo.fe8;
            //        data.Fe4 = vo.fe9;
            //        data.Fe5 = vo.fe10;
            //        data.Fe6 = vo.fe11;
            //        data.Fe7 = vo.fe12;
            //        data.Fe8 = vo.fe13;
            //        data.Fe9 = vo.fe14;
            //        data.Fe10 = vo.fe15;
            //        data.MFe1 = vo.mfe1;
            //        data.MFe2 = vo.mfe2;
            //        data.MFe3 = vo.mfe3;
            //        data.MFe4 = vo.mfe4;
            //        data.MFe5 = vo.mfe5;
            //        data.MFe6 = vo.mfe6;
            //        data.MFe7 = vo.mfe7;
            //        data.MFe8 = vo.mfe8;
            //        data.MFe9 = vo.mfe9;
            //        data.MFe10 = vo.mfe10;
            //        data.NFe1 = vo.nfe6;
            //        data.NFe2 = vo.nfe7;
            //        data.NFe3 = vo.nfe8;
            //        data.NFe4 = vo.nfe9;
            //        data.CreateTime = DateTime.Now;
            //    }
            //}
            #endregion
            string text = textBox1.Text;
            int index = text.IndexOf('}');
            if (text.IndexOf('}') > -1)
            {
                //ZhXinVo vo = JsonConvert.DeserializeObject<ZhXinVo>(text);
                //DeviceInfo data = new DeviceInfo();
                //data.Temp = vo.msg.data.Y001;
                //MessageBox.Show(data.Temp.ToString());
            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            DateTime dt = GetDateTime(long.Parse(textBox2.Text));
            MessageBox.Show(dt.ToString());
           
        }
        public  DateTime GetDateTime(long timeStamp)
        {
            DateTime time = new DateTime();
            try
            {
                DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long lTime = long.Parse(timeStamp + "0000000");
                TimeSpan toNow = new TimeSpan(lTime);
                time = dtStart.Add(toNow);
            }
            catch
            {
                time = DateTime.Now.AddDays(-30);
            }
            return time;
        }
    }
}
